package com.evil.common.log.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.Optional;

@AllArgsConstructor
public enum OperationTypeEnum {

    INSERT(1, "插入", "insert"),
    UPDATE(2, "更新", "update"),
    DELETE(1, "删除", "delete");

    @Getter
    private final int id;
    @Getter
    private final String name;
    @Getter
    private final String title;

    public static Optional<OperationTypeEnum> findById(int id) {
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static OperationTypeEnum checkInsetOrUpdate(Object targetId) {
        return ObjectUtils.isEmpty(targetId) ? INSERT : UPDATE;
    }
}
